package com.itheima;


import com.itheima.dao.BookDao;
import com.itheima.service.BookService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 首先使用ApplicationContext创建IOC接口
 * 接口不能创对象，调用ClassPathXmlApplicationContext方法实现，参数是配置文件名
 * 接着调用getBean方法，这个方法获取的都是Object对象，所以要强转
 */
public class App1 {

    public static void main(String[] args) {

        //获取IOC容器
        ApplicationContext cx = new ClassPathXmlApplicationContext("applicationContext.xml");

        //获取bean
        BookDao bookDao = (BookDao) cx.getBean("bookDao");

        bookDao.save();

        //显然这里面两句话都输出了，但并没有配置DI是因为在BookServiceImpl中new 了BookDao对象
        BookService bookService = (BookService) cx.getBean("bookService");

        bookService.save();
    }
}
